package org.feifei.basic.util;

/**
 * 工具类, 返回json数据格式
 * @param <T>
 */
public class CommonResult<T> {

    private String msg;

    private Boolean success;

    private T data;

    private  CommonResult(String msg, Boolean success, T data) {
        this.msg = msg;
        this.success = success;
        this.data = data;
    }
    /** 携带数据的成功返回 */
    public static<T> CommonResult ok(T data) {
        return new CommonResult(null, true, data);
    }
    /** 不携带数据的成功返回*/
    public static CommonResult ok() {
        return new CommonResult(null, true, null);
    }

    /** 不携带错误信息的返回 */
    public static CommonResult failure() {
        return new CommonResult(null, false, null);
    }
    /** 携带错误信息的返回 */
    public static CommonResult failure(String msg) {
        return new CommonResult(msg, false, null);
    }
    /** 携带错误信息的返回 */
    public static<T> CommonResult failure(T data) {
        return new CommonResult(null, false, data);
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
